
package biblio.domain;


import biblio.util.AuxClass;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;


/**
 *
 * @author mephisto
 */
@Entity
@Table(name="book")
public class Book implements Serializable
{
    @Id
    @GeneratedValue
    @Column(name="book_id")
    public int getId()
    {
        return id;
    }

    public void setId(int id) 
    {
        this.id = id;
    }

    @Column(name="isbn")
    public String getISBN()
    {
        return ISBN;
    }

    public void setISBN(String ISBN)
    {
        this.ISBN = ISBN;
    }

    @Column(name="pages_num")
    public int getPagesNumber()
    {
        return pagesNumber;
    }

    public void setPagesNumber(int pagesNumber)
    {
        this.pagesNumber = pagesNumber;
    }

    @Column(name="publishing_date")
    @Temporal(javax.persistence.TemporalType.DATE)
    public Date getPublishingDate()
    {
        return publishingDate;
    }

    public void setPublishingDate(Date publishingDate)
    {
        this.publishingDate = publishingDate;
    }

    public String getTitle()
    {
        return title;
    }

    public void setTitle(String title)
    {
        this.title = title;
    }

    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(
        name = "author_book",
        joinColumns = { @JoinColumn(name = "book_id") },
        inverseJoinColumns = { @JoinColumn(name = "author_id") })
    public Set<Author> getAuthors()
    {
        return authors;
    }

    public void setAuthors(Set<Author> authors)
    {
        this.authors = authors;
    }


    @ManyToOne(cascade = CascadeType.MERGE)
    @JoinColumn(name="category_id")
    public Category getCategory()
    {
        return category;
    }

    public void setCategory(Category category)
    {
        this.category = category;
    }

    @Override
    public String toString()
    {
        return new StringBuilder().append(id).append("-").append(title).toString();
    }


    private int id;
    private String title;
    private int pagesNumber;
    private String ISBN;
    private Date publishingDate;
    private Set<Author> authors = new HashSet<Author>(0);
    private Category category;
}
